package tdjson

import (
	
	
	

	

	
)

// Encoder is a simple wrapper around jx.Encoder to conform TL type system.
type Encoder struct {
	*jx.Writer
}

// PutID serializes given typeID.
func ( Encoder) ( string) {
	.Writer.FieldStart(TypeField)
	.Writer.Str()
}

// PutInt serializes v as signed 32-bit integer.
func ( Encoder) ( int) {
	.Writer.Int()
}

// PutBool serializes boolean.
func ( Encoder) ( bool) {
	.Writer.Bool()
}

// PutUint16 serializes unsigned 16-bit integer.
func ( Encoder) ( uint16) {
	.Writer.UInt32(uint32())
}

// PutInt32 serializes signed 32-bit integer.
func ( Encoder) ( int32) {
	.Writer.Int32()
}

// PutUint32 serializes unsigned 32-bit integer.
func ( Encoder) ( uint32) {
	.Writer.UInt32()
}

// PutInt53 serializes v as int53.
func ( Encoder) ( int64) {
	.Writer.Int64()
}

// PutLong serializes v as int64.
func ( Encoder) ( int64) {
	var  [32]byte
	 := append([:0], '"')
	 = strconv.AppendInt(, , 10)
	 = append(, '"')
	.Writer.Raw()
}

// PutUint64 serializes v as unsigned 64-bit integer.
func ( Encoder) ( uint64) {
	// FIXME(tdakkota): TDLib API has no uint64 fields
	// 	so this encoding may incorrect.
	.Writer.UInt64()
}

// PutDouble serializes v as 64-bit floating point.
func ( Encoder) ( float64) {
	.Writer.Float64()
}

// PutInt128 serializes v as 128-bit signed integer.
func ( Encoder) ( bin.Int128) {
	// FIXME(tdakkota): neither TDLib API nor Telegram API has no Int128/Int256 fields
	// 	so this encoding may incorrect.
	.Writer.Str(hex.EncodeToString([:]))
}

// PutInt256 serializes v as 256-bit signed integer.
func ( Encoder) ( bin.Int256) {
	// FIXME(tdakkota): neither TDLib API not Telegram API has no Int128/Int256 fields
	// 	so this encoding may incorrect.
	.Writer.Str(hex.EncodeToString([:]))
}

// PutString serializes bare string.
func ( Encoder) ( string) {
	.Writer.Str()
}

// PutBytes serializes bare byte string.
func ( Encoder) ( []byte) {
	// See https://core.telegram.org/tdlib/docs/td__json__client_8h.html
	//
	// ... fields of bytes type are base64 encoded and then stored as String ...
	.Writer.Str(base64.RawURLEncoding.EncodeToString())
}

// StripComma deletes last comma, if any.
//
// Useful for code generation to avoid last field/element tracking.
func ( Encoder) () {
	if  := len(.Buf);  > 0 && .Buf[-1] == ',' {
		.Buf = .Buf[:-1]
	}
}