// Size returns the number of bytes the value v has in its AMF0 representation.
// Eg: a value v of "test" will return 7 (3 bytes for the header, 4 bytes for the string Size)
// Eg: a value v of 5 will return 9 (1 byte for the header, 8 bytes for the number)
Size returns the number of bytes the value v has in its AMF0 representation.
Eg: a value v of "test" will return 7 (3 bytes for the header, 4 bytes for the string Size)
Eg: a value v of 5 will return 9 (1 byte for the header, 8 bytes for the number)
// Size returns the number of bytes the value v has in its AMF0 representation . // Eg : a value v of " test " will return 7 ( 3 bytes for the header 4 bytes for the string Size ) // Eg : a value v of 5 will return 9 ( 1 byte for the header 8 bytes for the number )
func Size(v interface{}) uint64 {
	switch v.(type) {
	case float64:
		return 9
	case bool:
		return 2
	case string:
		length := uint64(len(v.(string)))
		if length < 65535 {
			return 3 + length
		} else {
			return 5 + length
		}
	case map[string]interface{}:
		var objSize uint64
		for k, val := range v.(map[string]interface{}) {
			objSize += Size(k) - 1 
			objSize += Size(val)
		}
		return objSize + 4 
	case nil:
		return 1
	case ECMAArray:
		var objSize uint64
		for k, val := range v.(ECMAArray) {
			objSize += Size(k)
			objSize += Size(val)
		}
		return objSize + 5 
	case time.Time:
		return 11
	default:
		return 0
	}
}
func Size ( v interface { } ) uint64 { switch v . ( type ) { case float64 : return 9 case bool : return 2 case string : length := uint64 ( len ( v . ( string ) ) ) if length < 65535 { return 3 + length } else { return 5 + length } case map [ string ] interface { } : var objSize uint64 for k , val := range v . ( map [ string ] interface { } ) { objSize += Size ( k ) - 1 objSize += Size ( val ) } return objSize + 4 case nil : return 1 case ECMAArray : var objSize uint64 for k , val := range v . ( ECMAArray ) { objSize += Size ( k ) objSize += Size ( val ) } return objSize + 5 case time . Time : return 11 default : return 0 } }
Size returns the number of bytes the value v has in its AMF0 representation.
Size returns the number of bytes the value v has in its AMF0 representation .
// A float64 spans 9 bytes (1 header byte + 8 data bytes) // A bool spans 2 bytes (1 header byte + 1 data byte) // A string's Size is variable. Depends if it is a Long String (strings with length >= 65535) or a normal String (length < 65535) + its data. // First check for normal string // If it is a normal string, its Size is 3 + n (3 header bytes + string Size) // If it is a long string, its Size is 5 + n (5 header bytes + string Size) // Calculate object Size recursively // objects don't store the TypeString (0x02) header in the key // Objects have a header of 1 byte and trailing marker of 3 bytes (0x00 0x00 0x09) // nil/null has a Size of 1 // Objects have a header of 5 bytes (1 byte to indicate ECMArray type, followed by 4 bytes for the associative count) // Dates have 11 bytes