Class: A2A::Types::FileWithBytes

Inherits:
FileBase show all
Defined in:
lib/a2a/types/part.rb

Overview

Represents a file with base64-encoded bytes

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from FileBase

from_h

Methods inherited from BaseModel

#==, #camelize, from_h, from_json, #hash, #to_h, #to_json, underscore, #valid?, #validate_array_type, #validate_inclusion, #validate_required, #validate_type

Constructor Details

#initialize(name:, mime_type:, bytes:) ⇒ FileWithBytes

Initialize a new file with bytes

Parameters:

  • name (String)

    The file name

  • mime_type (String)

    The MIME type

  • bytes (String)

    Base64-encoded file content



217
218
219
220
221
222
# File 'lib/a2a/types/part.rb', line 217

def initialize(name:, mime_type:, bytes:)
  @name = name
  @mime_type = mime_type
  @bytes = bytes
  validate!
end

Instance Attribute Details

#bytesObject (readonly)

Returns the value of attribute bytes.



209
210
211
# File 'lib/a2a/types/part.rb', line 209

def bytes
  @bytes
end

#mime_typeObject (readonly)

Returns the value of attribute mime_type.



209
210
211
# File 'lib/a2a/types/part.rb', line 209

def mime_type
  @mime_type
end

#nameObject (readonly)

Returns the value of attribute name.



209
210
211
# File 'lib/a2a/types/part.rb', line 209

def name
  @name
end

Instance Method Details

#contentString

Get the decoded file content

Returns:

  • (String)

    The decoded binary content



228
229
230
231
# File 'lib/a2a/types/part.rb', line 228

def content
  require "base64"
  Base64.decode64(@bytes)
end

#sizeInteger

Get the file size in bytes

Returns:

  • (Integer)

    The file size



237
238
239
# File 'lib/a2a/types/part.rb', line 237

def size
  content.bytesize
end

#validate!Object (private)



243
244
245
246
247
248
# File 'lib/a2a/types/part.rb', line 243

def validate!
  validate_required(:name, :mime_type, :bytes)
  validate_type(:name, String)
  validate_type(:mime_type, String)
  validate_type(:bytes, String)
end